package com.ys168.gam.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import com.ys168.gam.download.DownloadStatus;

/**
 * @author Jason Krebs
 * @since 2015年6月12日
 */
public class ResourceLoader {

    private static Map<DownloadStatus, ImageIcon> DOWNLOADSATUS_ICONS = new HashMap<DownloadStatus, ImageIcon>();

    public static void load() {
        DOWNLOADSATUS_ICONS.put(DownloadStatus.UN_STSARTED,
                new ImageIcon(ResourceLoader.class.getResource("/image/gray.gif")));
        DOWNLOADSATUS_ICONS.put(DownloadStatus.DOWNLOADING,
                new ImageIcon(ResourceLoader.class.getResource("/image/yellow.gif")));
        DOWNLOADSATUS_ICONS.put(DownloadStatus.DOWNLOADED_SUCCESSED,
                new ImageIcon(ResourceLoader.class.getResource("/image/green.gif")));
        DOWNLOADSATUS_ICONS.put(DownloadStatus.DOWNLOAD_FAILED,
                new ImageIcon(ResourceLoader.class.getResource("/image/red.gif")));
    }

    public static Icon getDownloadStatusIcon(DownloadStatus status) {
        return DOWNLOADSATUS_ICONS.get(status);
    }
    
    public static String encodeWord(String word) {
        try {
            return URLEncoder.encode(word, "UTF-8");
        }
        catch (UnsupportedEncodingException e) {
            // Unreachable exception
        }
        return "";
    }
}
